import {Component, Input, OnInit} from '@angular/core';
import {RoleGroup} from "../../../../model/RoleGroup";
import {AlertService} from "../../../../services/alert.service";
import {ManageService} from "../../../../services/manage.service";

@Component({
  selector: 'app-gwedit',
  templateUrl: './gwedit.component.html',
  styleUrls: ['./gwedit.component.css']
})
export class GweditComponent implements OnInit {
  @Input()id: string
  @Input()optype:string
  role:RoleGroup
  constructor(private manageService:ManageService,
              private alertService:AlertService) {
    this.role = new RoleGroup()
  }

  ngOnInit(): void {
    if(this.optype=="update"){
      this.getRoleByid();
    }
  }

  getRoleByid(){
    this.manageService.getRoleGroupById(this.id).then((data:any)=>{
      if(data.msg == "ok"){
        this.role = data.obj
      }else{
        this.alertService.showError("根据id获取岗位信息失败")
      }
    })
  }

  save(){
    this.manageService.saveRoleGroup(this.role).then((data:any)=>{
      if(data.msg == "ok"){
        this.alertService.showSuccess("设置岗位信息成功")
      }else{
        this.alertService.showError("设置岗位信息失败")
      }
    })
  }

}
